package class12;

public class Calculator {
    public String resultMsg="";


    public double Add(double a, double b) {
        return a + b;
    }

    public double sub(double a, double b) {
        return a - b;
    }

    public double mul(double a, double b) {
        return a * b;
    }

    public double div(double a, double b) {
        return a / b;
    }
    public boolean getResult(double a, double b,String sym) {
        double result;
                switch (sym) {
                    case "+":
                        result = Add(a, b);
                        resultMsg = "结果是:" + result;
                        return true;
                    case "-":
                        result= sub(a, b);
                        resultMsg = "结果是:" + result;
                        return true;
                    case "*":
                        result = mul(a, b);
                        resultMsg = "结果是:" + result;
                        return true;
                    case "/":
                        result = div(a, b);
                        resultMsg = "结果是:" + result;
                        return true;
                    default:
                        resultMsg="请输入正确参数！";
                        return false;
                }
    }
    public String getResult(){return resultMsg;}
}



